﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllSubCategorybyCategoryIDDataAction:BestLifeDataAction<List<Sub_Category>>
    {
         private string GvCat_ID;

         public BestLifeGetAllSubCategorybyCategoryIDDataAction(string PCat_ID)
        {
            GvCat_ID = PCat_ID;
        }

         public override List<Sub_Category> Body(SqlConnection PConn)
        {
            try
            {
                List<Sub_Category> LvList = new List<Sub_Category>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetSubCategoryByCatID";
                LvCommand.Parameters.Add(new SqlParameter("@CatID", GvCat_ID));

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                   
                    Sub_Category LvSub_Category = new Sub_Category();
                     LvSub_Category.Subcat_ID = LvReader.GetValue(0).ToString();
                    LvSub_Category.Subcat_ID=LvReader.GetValue(1).ToString();
                     LvSub_Category.Sub_Cat_Name = LvReader.GetValue(2).ToString();
                     LvSub_Category.Description = LvReader.GetValue(3).ToString();
                      LvSub_Category.Status = LvReader.GetValue(4).ToString();
                     LvSub_Category.User_Id = LvReader.GetValue(5).ToString();
                     //LvSub_Category.Date_Create = LvReader.GetValue(6).ToString();
                     //LvSub_Category.Last_Modify = LvReader.GetValue(7).ToString();
                    LvSub_Category.User_Modify = LvReader.GetValue(8).ToString();

                    LvList.Add(LvSub_Category);
                }
                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    
    }
}
